package com.oocl.ajax.util;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

/**
 * @description: 
 * @author  XIEMI2
 * @date Aug 1, 2017 8:17:31 PM
 * @version 1.0
 */
public class DBUtil {
	private static BasicDataSource ds;
	private static Properties pro;
	private static InputStream in;
	
	static{
		try {
			ds = new BasicDataSource();
			in = new BufferedInputStream(new FileInputStream("D:/bin/apache-tomcat-7.0.79/wtpwebapps/ajax/WEB-INF/classes/db.properties"));
			pro = new Properties();
			pro.load(in);
			ds.setDriverClassName(pro.getProperty("driverClass"));
			ds.setUsername(pro.getProperty("userName"));
			ds.setPassword(pro.getProperty("pwd"));
			ds.setUrl(pro.getProperty("url"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 
	 * @return
	 */
	public static Connection createConnectionWithDataSource(){
		Connection con = null;
		try {
			con = ds.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
	

}



